package b.c.a.b;

import com.huawei.hms.framework.common.ContainerUtils;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.WeakHashMap;

/* compiled from: SafeIterableMap */
public class b<K, V> implements Iterable<Entry<K, V>> {
    public c<K, V> a;
    public c<K, V> b;
    public WeakHashMap<f<K, V>, Boolean> c = new WeakHashMap();
    public int d = 0;

    /* compiled from: SafeIterableMap */
    public static class c<K, V> implements Entry<K, V> {
        public final K a;
        public final V b;
        public c<K, V> c;
        public c<K, V> d;

        public c(K k, V v) {
            this.a = k;
            this.b = v;
        }

        public boolean equals(Object obj) {
            boolean z = true;
            if (obj == this) {
                return true;
            }
            if (!(obj instanceof c)) {
                return false;
            }
            c cVar = (c) obj;
            if (!(this.a.equals(cVar.a) && this.b.equals(cVar.b))) {
                z = false;
            }
            return z;
        }

        public K getKey() {
            return this.a;
        }

        public V getValue() {
            return this.b;
        }

        public int hashCode() {
            return this.a.hashCode() ^ this.b.hashCode();
        }

        public V setValue(V v) {
            throw new UnsupportedOperationException("An entry modification is not supported");
        }

        public String toString() {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(this.a);
            stringBuilder.append(ContainerUtils.KEY_VALUE_DELIMITER);
            stringBuilder.append(this.b);
            return stringBuilder.toString();
        }
    }

    /* compiled from: SafeIterableMap */
    public interface f<K, V> {
        void a(c<K, V> cVar);
    }

    /* compiled from: SafeIterableMap */
    public class d implements Iterator<Entry<K, V>>, f<K, V> {
        public c<K, V> a;
        public boolean b = true;

        public void a(c<K, V> cVar) {
            c<K, V> cVar2 = this.a;
            if (cVar == cVar2) {
                c cVar3 = cVar2.d;
                this.a = cVar3;
                this.b = cVar3 == null;
            }
        }

        public boolean hasNext() {
            boolean z = true;
            if (this.b) {
                if (b.this.a == null) {
                    z = false;
                }
                return z;
            }
            c cVar = this.a;
            if (cVar == null || cVar.c == null) {
                z = false;
            }
            return z;
        }

        public Object next() {
            if (this.b) {
                this.b = false;
                this.a = b.this.a;
            } else {
                c cVar = this.a;
                this.a = cVar != null ? cVar.c : null;
            }
            return this.a;
        }
    }

    /* compiled from: SafeIterableMap */
    public static abstract class e<K, V> implements Iterator<Entry<K, V>>, f<K, V> {
        public c<K, V> a;
        public c<K, V> b;

        public e(c<K, V> cVar, c<K, V> cVar2) {
            this.a = cVar2;
            this.b = cVar;
        }

        public void a(c<K, V> cVar) {
            c cVar2 = null;
            if (this.a == cVar && cVar == this.b) {
                this.b = null;
                this.a = null;
            }
            c<K, V> cVar3 = this.a;
            if (cVar3 == cVar) {
                this.a = b(cVar3);
            }
            cVar3 = this.b;
            if (cVar3 == cVar) {
                cVar = this.a;
                if (!(cVar3 == cVar || cVar == null)) {
                    cVar2 = c(cVar3);
                }
                this.b = cVar2;
            }
        }

        public abstract c<K, V> b(c<K, V> cVar);

        public abstract c<K, V> c(c<K, V> cVar);

        public boolean hasNext() {
            return this.b != null;
        }

        public Object next() {
            c cVar = this.b;
            c cVar2 = this.a;
            cVar2 = (cVar == cVar2 || cVar2 == null) ? null : c(cVar);
            this.b = cVar2;
            return cVar;
        }
    }

    /* compiled from: SafeIterableMap */
    public static class a<K, V> extends e<K, V> {
        public a(c<K, V> cVar, c<K, V> cVar2) {
            super(cVar, cVar2);
        }

        public c<K, V> b(c<K, V> cVar) {
            return cVar.d;
        }

        public c<K, V> c(c<K, V> cVar) {
            return cVar.c;
        }
    }

    /* compiled from: SafeIterableMap */
    public static class b<K, V> extends e<K, V> {
        public b(c<K, V> cVar, c<K, V> cVar2) {
            super(cVar, cVar2);
        }

        public c<K, V> b(c<K, V> cVar) {
            return cVar.c;
        }

        public c<K, V> c(c<K, V> cVar) {
            return cVar.d;
        }
    }

    public c<K, V> b(K k) {
        c<K, V> cVar = this.a;
        while (cVar != null && !cVar.a.equals(k)) {
            cVar = cVar.c;
        }
        return cVar;
    }

    public d c() {
        d dVar = new d();
        this.c.put(dVar, Boolean.FALSE);
        return dVar;
    }

    public c<K, V> d(K k, V v) {
        c cVar = new c(k, v);
        this.d++;
        c cVar2 = this.b;
        if (cVar2 == null) {
            this.a = cVar;
            this.b = cVar;
            return cVar;
        }
        cVar2.c = cVar;
        cVar.d = cVar2;
        this.b = cVar;
        return cVar;
    }

    public V e(K k) {
        c b = b(k);
        if (b == null) {
            return null;
        }
        this.d--;
        if (!this.c.isEmpty()) {
            for (f a : this.c.keySet()) {
                a.a(b);
            }
        }
        c cVar = b.d;
        if (cVar != null) {
            cVar.c = b.c;
        } else {
            this.a = b.c;
        }
        c cVar2 = b.c;
        if (cVar2 != null) {
            cVar2.d = cVar;
        } else {
            this.b = cVar;
        }
        b.c = null;
        b.d = null;
        return b.b;
    }

    /* JADX WARNING: Missing block: B:22:0x0048, code skipped:
            if (r3.hasNext() != false) goto L_0x0053;
     */
    /* JADX WARNING: Missing block: B:24:0x0050, code skipped:
            if (((b.c.a.b.b.e) r7).hasNext() != false) goto L_0x0053;
     */
    /* JADX WARNING: Missing block: B:25:0x0053, code skipped:
            r0 = false;
     */
    /* JADX WARNING: Missing block: B:26:0x0054, code skipped:
            return r0;
     */
    public boolean equals(java.lang.Object r7) {
        /*
        r6 = this;
        r0 = 1;
        if (r7 != r6) goto L_0x0004;
    L_0x0003:
        return r0;
    L_0x0004:
        r1 = r7 instanceof b.c.a.b.b;
        r2 = 0;
        if (r1 != 0) goto L_0x000a;
    L_0x0009:
        return r2;
    L_0x000a:
        r7 = (b.c.a.b.b) r7;
        r1 = r6.d;
        r3 = r7.d;
        if (r1 == r3) goto L_0x0013;
    L_0x0012:
        return r2;
    L_0x0013:
        r1 = r6.iterator();
        r7 = r7.iterator();
    L_0x001b:
        r3 = r1;
        r3 = (b.c.a.b.b.e) r3;
        r4 = r3.hasNext();
        if (r4 == 0) goto L_0x0044;
    L_0x0024:
        r4 = r7;
        r4 = (b.c.a.b.b.e) r4;
        r5 = r4.hasNext();
        if (r5 == 0) goto L_0x0044;
    L_0x002d:
        r3 = r3.next();
        r3 = (java.util.Map.Entry) r3;
        r4 = r4.next();
        if (r3 != 0) goto L_0x003b;
    L_0x0039:
        if (r4 != 0) goto L_0x0043;
    L_0x003b:
        if (r3 == 0) goto L_0x001b;
    L_0x003d:
        r3 = r3.equals(r4);
        if (r3 != 0) goto L_0x001b;
    L_0x0043:
        return r2;
    L_0x0044:
        r1 = r3.hasNext();
        if (r1 != 0) goto L_0x0053;
    L_0x004a:
        r7 = (b.c.a.b.b.e) r7;
        r7 = r7.hasNext();
        if (r7 != 0) goto L_0x0053;
    L_0x0052:
        goto L_0x0054;
    L_0x0053:
        r0 = 0;
    L_0x0054:
        return r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: b.c.a.b.b.equals(java.lang.Object):boolean");
    }

    public int hashCode() {
        Iterator it = iterator();
        int i = 0;
        while (true) {
            e eVar = (e) it;
            if (!eVar.hasNext()) {
                return i;
            }
            i += ((Entry) eVar.next()).hashCode();
        }
    }

    public Iterator<Entry<K, V>> iterator() {
        a aVar = new a(this.a, this.b);
        this.c.put(aVar, Boolean.FALSE);
        return aVar;
    }

    public String toString() {
        StringBuilder g = c.b.a.a.a.g("[");
        Iterator it = iterator();
        while (true) {
            e eVar = (e) it;
            if (eVar.hasNext()) {
                g.append(((Entry) eVar.next()).toString());
                if (eVar.hasNext()) {
                    g.append(", ");
                }
            } else {
                g.append("]");
                return g.toString();
            }
        }
    }
}
